/*
 ============================================================================
 Name		: FM_RadioAppView.cpp
 Author	  : kamal
 Copyright   : Your copyright notice
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "FM_RadioAppView.h"
#include <aknmessagequerydialog.h>
#include <eikstart.h>

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CFM_RadioAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFM_RadioAppView* CFM_RadioAppView::NewL(const TRect& aRect)
{
	CFM_RadioAppView* self = CFM_RadioAppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFM_RadioAppView* CFM_RadioAppView::NewLC(const TRect& aRect)
{
	CFM_RadioAppView* self = new (ELeave) CFM_RadioAppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CFM_RadioAppView::ConstructL(const TRect& aRect)
{
	// Create a window for this application view
	CreateWindowL();
	iMyFont = NULL;
	
	iAlphaValue = 70;
	iXCordinates = 35;
	iYCordinates = 85;
	iPixel = 30;
	
	CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
	TFontSpec fontspec(_L("Series 60 Sans Regular"), screenDevice->VerticalPixelsToTwips(iPixel));
	CFont* pFont = 0;
	screenDevice->GetNearestFontInTwips(pFont, fontspec);
	screenDevice->ReleaseFont(pFont);
	iMyFont = pFont;
		
	
	iFrequencyDrawingPositionTimer = CPeriodic::NewL(CActive::EPriorityStandard);
	iFrequencyDrawingPositionTimer->Start(0, 600000, TCallBack(CFM_RadioAppView::Period, this));

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::CFM_RadioAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CFM_RadioAppView::CFM_RadioAppView()
{
	// No implementation required
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::~CFM_RadioAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CFM_RadioAppView::~CFM_RadioAppView()
{
	// No implementation required
	
	if(iMyFont)
	{
	//	delete iMyFont;
		iMyFont = NULL;
	}
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CFM_RadioAppView::Draw(const TRect& /*aRect*/) const
{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();
	
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.SetBrushColor(KRgbBlack);
	gc.SetPenColor(KRgbBlack);
	TRect drawRect(Rect());
	gc.Clear(drawRect);
	//const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont);
	
	//gc.SetPenSize(TSize(100,100));
	TRgb rgb(255,255,255);
	rgb.SetAlpha(iAlphaValue);
	//gc.SetPenColor(KRgbBlack);
	gc.SetPenColor(rgb);
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	//gc.SetBrushStyle(CGraphicsContext::ENullBrush);
	gc.UseFont(iMyFont);
	// Gets the control's extent
	//
	//gc.DrawText(_L("97.00"),TPoint(Rect().Width()/2,Rect().Height()/2));
	//gc.DrawText(_L("97.00"),TPoint(0,Rect().Height()/2));
	gc.DrawText(_L("97.00"),TPoint(iXCordinates,iYCordinates));
	gc.DrawText(_L("97.00"),TPoint(iXCordinates - 50,iYCordinates - 50 ));
	gc.DrawText(_L("97.00"),TPoint(iXCordinates + 50,iYCordinates + 50 ));
	//gc.DrawText(_L("97.00"), TPoint(iPosition.iX, iPosition.iY - iStatusMessageDescent));

	// Clears the screen
	//gc.Clear(drawRect);
	
	gc.DiscardFont();

}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CFM_RadioAppView::SizeChanged()
{
	
	//iMyFont = AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont);
	
	/*CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
	TInt pixel = 200;
	//TFontSpec fontspec(_L("Series 60 Sans SemiBold"), screenDevice->VerticalPixelsToTwips(pixel));
	TFontSpec fontspec(_L("Series 60 Sans Regular"), screenDevice->VerticalPixelsToTwips(pixel));
	//fontspec.iTypeface = TTypeface::ESerif;
	//fontspec.iMyFontStyle = TFontStyle::ESub;
	CFont* pFont = 0;
	screenDevice->GetNearestFontInTwips(pFont, fontspec);
	screenDevice->ReleaseFont(pFont);

	if(iMyFont==NULL)
	{
		iMyFont = pFont;
	}

	
	iStatusMessageHeight = 1.5 * iMyFont->HeightInPixels();
	iStatusMessageDescent = iStatusMessageHeight - (iStatusMessageHeight + iMyFont->AscentInPixels()) / 2;
*/	DrawNow();
}

// -----------------------------------------------------------------------------
// CFM_RadioAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CFM_RadioAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
}




TInt CFM_RadioAppView::Period(TAny * aPtr)
{
	((CFM_RadioAppView*) aPtr)->doPeriod();
	return TRUE;
}

		
void CFM_RadioAppView::doPeriod()
{
	CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
	TInt pixel = 0;
	//pixel = iPixel + 80;
	if(iPixel > 400)
		iPixel = 80;
	iPixel +=80; 
	pixel = iPixel;
	TFontSpec fontspec(_L("Series 60 Sans Regular"), screenDevice->VerticalPixelsToTwips(pixel));
	CFont* pFont = 0;
	screenDevice->GetNearestFontInTwips(pFont, fontspec);
	screenDevice->ReleaseFont(pFont);
	//if(iMyFont==NULL)
	{
		iMyFont = pFont;
	}
	
	if(iAlphaValue < 30 )
		iAlphaValue = 100;
	iAlphaValue-=50;
	
	if(iXCordinates > 700 )
		iXCordinates = 10;
	iXCordinates += 10 ;
	
	if(iYCordinates > 700 )
		iYCordinates = 10;
	iYCordinates +=10;
	DrawNow();
}

	

// End of File
